home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue82 / misc / raghu / code.asm.txt next >
Encoding:
Text File  |  2002-09-01  |  4.7 KB  |  109 lines

  1. org 0x07c00             ; Start address 0000:7c00 
  2. jmp short begin_boot   ; Jump to start of boot routine & skip other data
  3.  
  4. bootmesg db "Our OS boot sector loading ......"
  5. pm_mesg  db "Switching to protected mode ...."
  6.  
  7. dw 512                   ; Bytes per sector
  8. db 1            ; Sectors per cluster
  9. dw 1            ; Number of reserved sectors
  10. db 2            ; Number of FATs
  11. dw 0x00e0        ; Number of dirs in root
  12. dw 0x0b40         ; Number of sectors in volume
  13. db 0x0f0                   ; Media descriptor
  14. dw 9            ; Number of sectors per FAT
  15. dw 18            ; Number of sectors per track
  16. dw 2            ; Number of read/write sectors
  17. dw 0            ; Number of hidden sectors
  18.  
  19. print_mesg :
  20.    mov ah,0x13        ; Fn 13h of int 10h writes a whole string on screen
  21.    mov al,0x00        ; bit 0 determines cursor pos,0->point to start after                           ; function call,1->point to last position written
  22.    mov bx,0x0007        ; bh -> screen page ie 0,bl = 07 ie white on black
  23.    mov cx,0x20        ; Length of string here 32 
  24.    mov dx,0x0000        ; dh->start cursor row,dl->start cursor column
  25.    int 0x10        ; call bios interrupt 10h
  26.    ret            ; Return to calling routine
  27.  
  28. get_key :
  29.    mov ah,0x00      
  30.    int 0x16              ; Get_key Fn 00h of 16h,read next character
  31.    ret
  32.  
  33. clrscr :
  34.    mov ax,0x0600      ; Fn 06 of int 10h,scroll window up,if al = 0 clrscr
  35.    mov cx,0x0000      ; Clear window from 0,0 
  36.    mov dx,0x174f      ; to 23,79
  37.    mov bh,0       ; fill with colour 0
  38.    int 0x10       ; call bios interrupt 10h
  39.    ret
  40.  
  41. begin_boot :
  42.    call clrscr             ; Clear the screen first
  43.    mov bp,bootmesg     ; Set the string ptr to message location
  44.    call print_mesg       ; Print the message
  45.    call get_key        ; Wait till a key is pressed
  46. bits 16
  47.    call clrscr        ; Clear the screen
  48.    mov ax,0xb800        ; Load gs to point to video memory
  49.    mov gs,ax        ; We intend to display a brown A in real mode
  50.    mov word [gs:0],0x641   ; display
  51.    call get_key          ; Get_key again,ie display till key is pressed    
  52.    mov bp,pm_mesg        ; Set string pointer       
  53.    call print_mesg        ; Call print_mesg subroutine   
  54.    call get_key          ; Wait till key is pressed
  55.    call clrscr             ; Clear the screen
  56.    cli            ; Clear or disable interrupts
  57.    lgdt[gdtr]        ; Load GDT    
  58.    mov eax,cr0        ; The lsb of cr0 is the protected mode bit
  59.    or al,0x01        ; Set protected mode bit
  60.    mov cr0,eax        ; Mov modified word to the control register
  61.    jmp codesel:go_pm
  62.  
  63. bits 32
  64. go_pm : 
  65.    mov ax,datasel   
  66.    mov ds,ax           ; Initialise ds & es to data segment
  67.    mov es,ax    
  68.    mov ax,videosel           ; Initialise gs to video memory
  69.    mov gs,ax    
  70.    mov word [gs:0],0x741 ; Display white A in protected mode
  71. spin : jmp spin             ; Loop
  72.  
  73. bits 16
  74. gdtr :
  75.    dw gdt_end-gdt-1      ; Length of the gdt
  76.    dd gdt               ; physical address of gdt
  77. gdt
  78. nullsel equ $-gdt           ; $->current location,so nullsel = 0h
  79. gdt0                ; Null descriptor,as per convention gdt0 is 0
  80.    dd 0               ; Each gdt entry is 8 bytes, so at 08h it is CS
  81.    dd 0                      ; In all the segment descriptor is 64 bits
  82. codesel equ $-gdt           ; This is 8h,ie 2nd descriptor in gdt
  83. code_gdt               ; Code descriptor 4Gb flat segment at 0000:0000h
  84.    dw 0x0ffff           ; Limit 4Gb  bits 0-15 of segment descriptor
  85.    dw 0x0000           ; Base 0h bits 16-31 of segment descriptor (sd)
  86.    db 0x00                  ; Base addr of seg 16-23 of 32bit addr,32-39 of sd    
  87.    db 0x09a           ; P,DPL(2),S,TYPE(3),A->Present bit 1,Descriptor                       ; privilege level 0-3,Segment descriptor 1 ie code                                  ; or data seg descriptor,Type of seg,Accessed bit
  88.    db 0x0cf           ; Upper 4 bits G,D,0,AVL ->1 segment len is page                                             ; granular, 1 default operation size is 32bit seg                                      ; AVL : Available field for user or OS
  89.                               ; Lower nibble bits 16-19 of segment limit
  90.    db 0x00           ; Base addr of seg 24-31 of 32bit addr,56-63 of sd
  91. datasel equ $-gdt           ; ie 10h, beginning of next 8 bytes for data sd
  92. data_gdt               ; Data descriptor 4Gb flat seg at 0000:0000h
  93.    dw 0x0ffff           ; Limit 4Gb
  94.    dw 0x0000           ; Base 0000:0000h
  95.    db 0x00           ; Descriptor format same as above
  96.    db 0x092
  97.    db 0x0cf
  98.    db 0x00
  99. videosel equ $-gdt           ; ie 18h,next gdt entry
  100.    dw 3999           ; Limit 80*25*2-1
  101.    dw 0x8000           ; Base 0xb8000
  102.    db 0x0b
  103.    db 0x92           ; present,ring 0,data,expand-up,writable
  104.    db 0x00           ; byte granularity 16 bit
  105.    db 0x00
  106. gdt_end
  107.  
  108. times 510-($-$$)  db 0  ; Fill bytes from present loc to 510 with 0s
  109.               dw 0x0aa55  ; Write aa55 in bytes 511,512 to indicate that                              ; it is a bootable sector.